﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.CustomerSys
{
	public partial class wfProxyVehicleManage : msBsc.Cls.BPProxy
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}


        //重构基类的回调处理函数，以strAction属性来判断是什么类型的回调，该变量的值对应前台的ACTION参数，如：按钮的名称等
        public override void InitialByParam()
        {
            if (this.gtGridRet != null)
            {
                if (this.gtGridRet.action == "load" || this.gtGridRet.action == "export")//处理GRID的数据原获取和数据导出
                {
                    DataSet ds = GetDisplayData(this.GetParamHtValue("gtGridID"), this.strAction, this.sCurrPageRadom);
                    if (ds != null && ds.Tables.Count > 0)
                        SetReturnDatatable(ds.Tables[0], "VEHICLE_INFO_ID");//BANK_ID为表的KEY字段，可填可不填
                }
            }
            if (this.strAction == "init")
            {
                showVehicleBrand();
            }
            base.InitialByParam();
        }

        //修改页面状态
        private void SetMode(string strMode)
        {
            EditMode = strMode; switch (strMode)
            {
                case "EDIT":
                    EnabledLinkBtn("btnEdit", false);
                    EnabledLinkBtn("btnSave", true);
                    EnabledLinkBtn("btnNotSave", true);
                    EnabledLinkBtn("btnConfirm", false);
                    EnabledLinkBtn("btnCancel", false);
                    this.ExecJScript("doEditGt('myGrid1');");
                    break;
                case "ADD":
                    EnabledLinkBtn("btnEdit", false);
                    EnabledLinkBtn("btnSave", true);
                    EnabledLinkBtn("btnNotSave", false);
                    EnabledLinkBtn("btnConfirm", false);
                    EnabledLinkBtn("btnCancel", false);
                    this.ExecJScript("doEditGt('myGrid1');");
                    break;
                case "VIEW":
                    EnabledLinkBtn("btnEdit", true);
                    EnabledLinkBtn("btnSave", false);
                    EnabledLinkBtn("btnNotSave", false);
                    EnabledLinkBtn("btnConfirm", true);
                    EnabledLinkBtn("btnCancel", true);
                    this.ExecJScript("doCancelGt('myGrid1');");
                    break;
            }
        }

        //获取数据原,"DP_DATA"字符一定不要改变，否则系统不能自动清除缓存
        private DataSet GetDisplayData(string strgtGridID, string strSrcF, string strsRadom)
        {
            if (strgtGridID == "myGrid1")
            {
                DataSet ds;
                if (strSrcF == "mFinder" || !this.SessionIsExists(strsRadom + "DP_DATA", "1"))//点击查询按钮时，或需要数据而没有缓存时，根据条件取出数据记录
                {
                    string brand = this.GetParamHtValue("brand");
                    string minseats = this.GetParamHtValue("minseats");
                    string maxseats = this.GetParamHtValue("maxseats");
                    string vehicleNumber = this.GetParamHtValue("vehicleNumber");
                    string startTime = this.GetParamHtValue("startTime");
                    string endTime = this.GetParamHtValue("endTime");
                    //string destination, string cityid, string countryid, int brand, int minseats, int maxseats, string vehicleNumber, string proxy, string startTime, string endTime
                    int iminSeats = 0;
                    int imaxSeats = 0;
                    int iBrand = 0;
                    int.TryParse(brand, out iBrand);
                    int.TryParse(minseats, out iminSeats);
                    int.TryParse(maxseats, out imaxSeats);
                    string proxyId = msBsc.SvRef.UserInfo.Operator;
                    using (msBsc.AppLogic.DataAlc.CBizVehicleInfo objCBizVehicleInfo = new msBsc.AppLogic.DataAlc.CBizVehicleInfo())
                    {
                        ds = objCBizVehicleInfo.GetNewVehicleList("", "", "", iBrand, iminSeats, imaxSeats, vehicleNumber, "", startTime, endTime,proxyId);
                    }


                    ds.AcceptChanges();
                    SetSession(strsRadom + "DP_DATA", ds, "1");
                    //查询时，将页面置为查看状态
                    if (strSrcF == "mFinder")
                        SetMode("VIEW");
                }
                else
                {
                    ds = (DataSet)this.GetSession(strsRadom + "DP_DATA", "1");
                }
                return ds;
            }
            else
            {
                return null;
            }
        }

        //获取车辆类型
        private void showVehicleBrand()
        {
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataTable dt = vehicleInfo.GetVehicleBrand();
                if (dt == null || dt.Rows.Count < 1)
                {
                    return;
                }
                DataRow dr = dt.NewRow();
                dr["enum_Value"] = "0";
                dr["enum_Name"] = "请选择";
                dt.Rows.InsertAt(dr, 0);
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(dt, "", "", 1, 100, "");
                this.ExecJScript(@"setSelect('vehicleBrand'," + retJson + ");");
            }
        }
	}
}